import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../../util/request-util";
import {DamAPI} from "../../peach-constants";
import {Observable} from "rxjs/Observable";
import {MsgResult} from "../../../../models/msg-result";

@Injectable()
export class ChainService {

  constructor(
    private requestUtil : RequestUtil
  ) { }
  /**
   *
   * @returns {Observable<MsgResult>|any}
   */
  getChainData(obj):Observable<MsgResult>{
    let params;
    if(obj.dataType == "dayData"){
      params = "format=json&yearNum="+obj.yearNum+"&monthOrWeekNum=0&pointType="+obj.pointType+"&dataType="+obj.dataType+"&startTime="+obj.startTime+"&endTime="+obj.endTime;
    }else{
      params = "format=json&yearNum="+obj.yearNum+"&monthOrWeekNum="+obj.monthOrWeekNum+"&pointType="+obj.pointType+"&dataType="+obj.dataType;
    }
    return this.requestUtil.get(DamAPI.getChain,params);
  }

  getExport(obj):Observable<MsgResult>{
    let params = "format=json&yearNum="+obj.yearNum+"&monthOrWeekNum="+obj.monthOrWeekNum+"&pointType="+obj.pointType+"&dataType="+obj.dataType;
    return this.requestUtil.get(DamAPI.getChain,params);
  }

  //不同用户不同站点
  getUserSiteData():Observable<MsgResult>{
    return this.requestUtil.get(DamAPI.getUserSite);
  }

}
